home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / memory / memman2b / mem_test.c < prev    next >
C/C++ Source or Header  |  1994-08-19  |  3KB  |  105 lines

  1. /***    Example of using memory manager to allocate extended memory
  2.         (c) R.J.Taylor August 1993,1994
  3. ***/
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <dos.h>
  9. #include <alloc.h>
  10.  
  11. #include "memory.h"
  12.  
  13. #define DEPTH 30
  14. #define WIDTH 1024
  15.  
  16. char buffs[DEPTH][WIDTH];
  17. char strat[4][30]={"CONVENTIONAL","EXPANDED","VIRTUAL","XMS"};
  18.  
  19. int farmemcmp (void far *s1,void far *s2,unsigned n) {
  20.     while (n--) if (*(((byte far*)s1)++)!=*(((byte far*)s2)++)) return -1;
  21.     return 0;
  22. }
  23.  
  24. void main (void) {
  25.  
  26.     int j,i;
  27.     mem_hand a;
  28.     byte far *p;
  29.     ulong initial_free=coreleft();
  30.  
  31.     /***    Load up our 60Kb buffer with junk from the first meg
  32.     ***/
  33.     for (i=0;i<DEPTH;i++) {
  34.         p=MK_FP(random(32767)*2,random(32767)*2);
  35.         memcpy((byte *)buffs[i],(byte *)p,WIDTH);
  36.     }
  37.  
  38.     /***    Loop, allocating each memory type in turn, then reading it back
  39.             to check it went down OK
  40.     ***/
  41.     for (j=0;j<4;j++) {
  42.  
  43.         /** Set strategy to (whatever) only
  44.         **/
  45.         i=strat[j][1];
  46.         strat[j][1]=0;
  47.         setXMstrat(strat[j]);
  48.         strat[j][1]=i;
  49.  
  50.         /** Indicate where we're trying to allocate
  51.         **/
  52.         printf("\n\nAttempting to allocate from %s ...\n",strat[j]);
  53.  
  54.         /** Allocate 100 lines of 1280 bytes each
  55.         **/
  56.         a=xalloc(WIDTH,DEPTH);
  57.  
  58.         if (a) {
  59.             /***    If we got a buffer
  60.             ***/
  61.             printf("Got it! [Overhead=%lu bytes]   ",initial_free-coreleft());
  62.             printf("mem_type() returns: [%s]\n",mem_type(a));
  63.             printf("Writing junk... \n");
  64.  
  65.             /***    Write our junk buffer
  66.             ***/
  67.             for (i=0;i<DEPTH;i++){
  68.  
  69.                 if (!xput((byte far*)buffs[i],i,a)) {
  70.                     printf("Couldn't write %d         \n",i);
  71.                 } else {
  72.                     printf("\rWrote %d        ",i);
  73.                 }
  74.  
  75.             }
  76.  
  77.             printf("\n");
  78.  
  79.             /***    Read it back
  80.             ***/
  81.             for (i=0;i<DEPTH;i++){
  82.  
  83.                 if (!(p=xget(i,a))) {
  84.                     printf("Couldn't read %d              \n",i);
  85.                 } else {
  86.                     if (farmemcmp(p,(byte far*)buffs[i],WIDTH)==0) {
  87.                         printf("\rRead %d ok         ",i);
  88.                     } else {
  89.                         printf("\rError reading %d!  \n",i);
  90.                     }
  91.                 }
  92.             }
  93.  
  94.         } else {
  95.  
  96.             printf("Couldn't allocate this resource\n");
  97.  
  98.         }
  99.  
  100.         /***    Free the buffer
  101.         ***/
  102.         xfree(a);
  103.     }
  104. }
  105.